package Demo2;

import java.sql.Array;
import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with Interllij IDEA.
 * Descriptiption:三个重要接口
 * User: 王澄慧
 * Date: 2022-04-09
 * Time: 20:34
 */
class  Student {
    //class Student implements Comparable<Student>{
    public String name;
    public int age;
    public double score;


    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}

    class AgeCompare implements Comparator<Student> {
        @Override
        public int compare(Student o1, Student o2) {

            return (o1.age-o2.age);
        }
    }
    class NameCompare implements Comparator<Student>{

        @Override
        public int compare(Student o1, Student o2) {
            return (o1.name.compareTo(o2.name));
        }
    }
    class ScoreCompare implements Comparator<Student>{

        @Override
        public int compare(Student o1, Student o2) {
            return ((int)(o1.score-o2.score));
        }
    }
    /*@Override
    public int compareTo(Student o) {
        return (int)(this.score-o.score);//score是double类型
        /*return (this.name.compareTo(o.name));
        return (this.age-o.age);大——小
        return (o.age-this.age);小——大
        if(this.score>o.score){
            return 1;
        } else if(this.score == o.score){
            return 0;
        }else {
            return -1;
        }
        if(this.name.compareTo(o.name) > 0){
            return 1;
        }else if (this.name.compareTo(o.name) == 0){
            return 0;
        }else {
            return -1;
        }
       if(this.age > o.age){
            return 1;
        }else if(this.age == o.age){
            return 0;
        }else {
            return -1;
        }*/

    public class test3 {
        public static void main(String[] args) {
            Student [] students = new Student[3];
            students[0] = new Student("张三",18,79.2);
            students[1] = new Student("李四",29,89.2);
            students[2] = new Student("ach",24,69.2);
            /*AgeCompare ageCompare = new AgeCompare();
            Arrays.sort(students,ageCompare);*/
            /*NameCompare nameCompare = new NameCompare();
            Arrays.sort(students,nameCompare);*/
            ScoreCompare scoreCompare = new ScoreCompare();
            Arrays.sort(students,scoreCompare);

            System.out.println(Arrays.toString(students));
        }
}
